/*
 * Connector.h
 *
 *  Created on: 2014. 6. 25.
 *      Author: jjaehuny
 */

#ifndef FRAMEWORK_DATABASE_CONNECTOR_H_
#define FRAMEWORK_DATABASE_CONNECTOR_H_

#include <memory>
#include <string>
#include <mutex>

#include <glog/logging.h>

#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>
#include <cppconn/connection.h>
#include <mysql_connection.h>

#include "../Memory/Lock_Function_new_Pool.h"
#include "../Util/TaskProcessing.h"
#include "../Macro.h"

namespace Framework { namespace Database {

/// connector class instance return class
class Connector;
Connector * get_connector (int type);

} /*Database*/ } /*Framework*/


namespace Framework { namespace Database {

class Command;

class Connector
{
public:
	struct Param {
		int type_;
		int count_;

		std::string host_;
		std::string user_;
		std::string pass_;
		std::string name_;
	};

public:
	Connector();
	virtual ~Connector();

	bool Connect(Param & param);
	void Sync_Execute(std::shared_ptr<Command> command);
	void Async_Execute(std::shared_ptr<Command> command);

private:
	void async();

private:
	Param param_;

	std::mutex mutex_;
	std::deque<std::shared_ptr<Command> > command_deque_;

	std::unique_ptr<Util::TaskProcessing> taskProcessing_;
};

} /*Database*/ } /*Framework*/

#endif /* FRAMEWORK_DATABASE_CONNECTOR_H_ */
